package org.example.zk3;

import org.apache.zookeeper.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.IOException;

public class TestZookeeper3 {
    private ZooKeeper zooKeeper;
    private String connectString = "192.168.110.97:2181";
    private int sessionTimeout = 10000;

    @Before
    public void init() throws IOException {
        zooKeeper = new ZooKeeper(connectString, sessionTimeout, new Watcher() {
            @Override
            public void process(WatchedEvent watchedEvent) {
                System.out.println(watchedEvent.getType().toString());
            }
        });
    }

    @After
    public void uninit() throws InterruptedException {
        zooKeeper.close();
    }

    @Test
    public void testZookeeper() {
        System.out.println("zookeeper = " + zooKeeper);
    }

    @Test
    public void testCreate() throws InterruptedException, KeeperException {
        String s = zooKeeper.create("/bigdata2", "kuai".getBytes(), ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
        System.out.println(s);
    }
}
